import { Switch, View } from "@tarojs/components";
import Taro from "@tarojs/taro";
import { Component } from "react";
import './setting.scss'

export default class Setting extends Component {
  state = Taro.getMySetting()

  onShareAppMessage() {
    return Taro.shareResult
  }

  onSettingChange = (key: string, value: any) => {
    this.setState({ [key]: value }, () => {
      Taro.setStorageSync('setting', this.state)
    })
  }

  render() {
    return (<View className='SettingPage'>
      <View className='cell'>
        <View className='left'>
          <View className='title'>
            自动保存
          </View>
          <View className='subTitle'>
            姓名已填，选择图片后自动合图并保存到相册
          </View>
        </View>
        <View className='right'>
          <Switch checked={this.state.autoSave} onChange={(e) => this.onSettingChange('autoSave', e.detail.value)} />
        </View>
      </View>
      <View className='cell'>
        <View className='left'>
          <View className='title'>
            水印姓名
          </View>
          <View className='subTitle'>
            姓名以水印的方式附加到图片
          </View>
        </View>
        <View className='right'>
          <Switch checked={this.state.watermarkName} onChange={(e) => this.onSettingChange('watermarkName', e.detail.value)} />
        </View>
      </View>
    </View>)
  }
}